<template>
  <div  class="content">
    <div class="head">
      <span>流程定义</span>
    </div>
    <Table :height="autoheight" stripe border :loading="loading" :columns="deployColumns" :data="deployData"></Table>
    <Page :total="totalSize" :current="page" :page-size="pageSize" @on-change="pageNum" @on-page-size-change="pageSizeChange" show-total></Page>
    <div>
      <Modal v-model="modalDeploy" title="温馨提示" @on-ok="flowDeploy"  @on-cancel="cancel">
        <p>确认要发布吗？</p>
      </Modal>
    </div>
   </div>
</template>
<script>
import { autoheight } from "../../../static/js/tool.js";
export default {
  data() {
    return {
      modalDeploy : false,
      autoheight:400,
      deployName: '',
      bpmnPath: '',
      totalSize: 0,
      pageSize: 20,
      page: 1,
      id: "",
      modalStart: false,
      roleArray: [],
      checkAllGroup: [],
      loading: true,
      deployColumns: [
        {
          title: "ID",
          key: "id",
          align: "center",
        },
        {
          title: "流程发布名称",
          key: "deployName",
          align: "center",
        },
        {
          title: "流程文件路径",
          key: "bpmnPath",
          align: "center",
        },
        {
          title: "操作",
          key: "action",
          width: 230,
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small"
                  },
                  on: {
                    click: () => {
                      this.showDeploy(params.row);
                    }
                  }
                },
                "流程发布"
              )
            ]);
          }
        }
      ],
      deployData: []
    };
  },
  mounted() {
    this.initData();
    autoheight(this,180)
  },
  methods: {
    initData() {
      this.loading = true;
      this.$http.post("/api/flow/bizflow/deploylib/getAll",{
         pageNum: this.page,
         pageSize: this.pageSize,
      }).then(res => {
        this.deployData = res.retBody.list;
        this.totalSize = res.retBody.total;
        this.loading = false;
      });
    },

    cancel() {},
    /**
     * 改变页码
     */
    pageNum(page) {
      this.loading = true;
      this.page = page;
      this.initData();
    },
    /**
     * 改变每页的条数
     */
    pageSizeChange(pageSize) {
      this.loading = true;
      this.pageSize = pageSize;
      this.initData();
    },

    // 流程发布提示框
    showDeploy(row){
      this.modalDeploy = true;
      this.deployName = row.deployName;
      this.bpmnPath = row.bpmnPath;
    },

    /**
     * 发布
     */
    flowDeploy() {
      this.$http.post("/api/flow/actflow/deploy/build", { 
        deployName: this.deployName,
        bpmnPath:  this.bpmnPath
        }).then(res => {
        if (res.retHead.code == "0000000") {
          this.$Message.success({
            top: 100,
            duration: 3,
            content: res.retHead.message
          });
        } else {
          this.$Message.warning({
            top: 100,
            duration: 3,
            content: res.retHead.message
          });
        }
        this.initData();
      });
    },
  }
};
</script>

